package edu.mis.modules.ledger;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;

import edu.mis.model.Kmye;
import edu.mis.model.Voucheritem;

public class GeneralLedgerController extends Controller{
	public void index() {
		render("generalLedger.html");
	}
	
	/**
	 * 获取总账
	 */
	public void get() {
		Integer captionId = getParaToInt("captionId");
		Integer year = getParaToInt("year");
		List<Kmye> list = Kmye.dao.find("select * from kmye where captionId = "+captionId+" and year(date)="+year+" and isInit = 0");
		int len = list.size();
		if(len==0){
			setAttr("success", false);
			setAttr("msg", "未查询到数据，请关账后再查!");
			renderJson();
		}else{
			JSONArray array = new JSONArray();
			for(int i=0;i<len;i++){
				Map<String, Object> data = new HashMap<String, Object>();
				// 年-月
				java.sql.Date date = list.get(i).get("date");
				java.text.SimpleDateFormat sformat = new java.text.SimpleDateFormat();
				sformat.applyPattern("yyyy-MM");
				data.put("date", sformat.format(date));
				// 借贷方向
				String bd=list.get(i).get("balanceDirection");
				data.put("balanceDirection",bd);
				// 期初余额
				double ob=list.get(i).get("openingBalance");
				data.put("openingBalance",ob);
				// 借方发生额
				double jffs=list.get(i).get("jffs");
				data.put("jffs", jffs);
				// 贷方发生额
				double dffs=list.get(i).get("dffs");
				data.put("dffs", dffs);
				// 本年累计借方发生
				double ljjf=list.get(i).get("ljjf");
				data.put("ljjf", ljjf);
				// 本年累计贷方发生
				double ljdf=list.get(i).get("ljdf");
				data.put("ljdf", ljdf);
				
				array.add(data);
			}
			renderJson(array.toJSONString());
		}
	}
}
